import requests
import json
from gen_ssdp import create_ssdp
from datetime import datetime


def push_data_to_ecsb(request_data):
    """
    推送数据到ecsb
    :return:
    """
    ssdp_str = create_ssdp()
    url = f"https://ecsb-dev.crb.cn/ecsb/gw/sys/rs/?ssdp={ssdp_str}"
    headers = {
        "Content-Type": "application/json"
    }
    data = {
    "REQUEST": {
        "API_ATTRS": {
            "Partner_ID": "12000000",
            "App_Sub_ID": "1200003H0002",
            "Sys_ID": "1200003H",
            "App_Token": "6318815045964181b3f30084e8d1ba4f",
            "Api_ID": "snowbeer.MES.test.SaveDataIOT",
            "Api_Version": "1.0",
            "Time_Stamp": datetime.now().strftime('%Y-%m-%d %H:%M:%S:%f')[:-3],
            "User_Token": "",
            "Sign": "NO_SIGN"
        },
        "REQUEST_DATA": request_data
    }
}
    response = requests.post(url, headers=headers, data=json.dumps(data))
    return response.status_code, response.text

